//
//  RootViewController.m
//  musicPlayer
//
//  Created by 康迂峰 on 14-5-16.
//  Copyright (c) 2014年 yufeng. All rights reserved.
//

#import "RootViewController.h"
#import "KYFAppDelegate.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self loadRootViewController];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    selectImage = [[UIImageView alloc]init];
    selectImage.frame = CGRectMake(0, -1, 320, 50);
    [self.tabBar addSubview:selectImage];
    self.tabBarItem.badgeValue = @"2";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    BOOL should = YES;
    if(tabBarController.selectedViewController == viewController) {
        should = NO;
    }
    return should;
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    
    switch (tabBarController.selectedIndex) {
        case 0:
            selectImage.image = [UIImage imageNamed:@"tab01"];
            break;
        case 1:
            selectImage.image = [UIImage imageNamed:@"tab02"];
            break;
        case 2:
            selectImage.image = [UIImage imageNamed:@"tab03"];
            break;
        case 3:
            selectImage.image = [UIImage imageNamed:@"tab04"];
            
        default:
            break;
    }

}

-(void)loadRootViewController {
    MusicKYFViewController *music = [[MusicKYFViewController alloc]init];
    UINavigationController *navOne = [[UINavigationController alloc]initWithRootViewController:music];
    
    tableKYFViewController *table = [[tableKYFViewController alloc]init];
    UINavigationController *navTwo = [[UINavigationController alloc]initWithRootViewController:table];
    
    TestOneViewController *testOne = [[TestOneViewController alloc]init];
    UINavigationController *navThr = [[UINavigationController alloc]initWithRootViewController:testOne];
    
    TestTwoViewController *testTwo = [[TestTwoViewController alloc]init];
    UINavigationController *navFou = [[UINavigationController alloc]initWithRootViewController:testTwo];
    
    self.viewControllers = [NSArray arrayWithObjects:navOne,navTwo,navThr,navFou, nil];
    
    [self setSelectedIndex:1];
    selectImage.image = [UIImage imageNamed:@"tab02"];
    
    [[self.tabBar.items objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d",[KYFAppDelegate instance].kang]];
    [[self.tabBar.items objectAtIndex:1] setBadgeValue:@"20"];
    [[self.tabBar.items objectAtIndex:2] setBadgeValue:@"30"];
    [[self.tabBar.items objectAtIndex:3] setBadgeValue:@"49"];
    
    self.delegate = self;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
